package com.acme.bankapp.account;

import com.acme.bankapp.domain.bank.Account;


/**
 * @author Andrey Alekov
 * Saving account implementation
 */
public class SavingAccount extends AbstractAccount{

	/*
	 * Constructor
	 * @param amount to initial balance value
	 */
	public SavingAccount(double amount) throws IllegalArgumentException {
		super(amount);
	}

	/*
	 * (non-Javadoc)
	 * @see com.acme.bankapp.account.AbstractAccount#deposit(double)
	 */
	@Override
	public void deposit(double amount) {
		balance += amount;
	}

	/*
	 * (non-Javadoc)
	 * @see com.acme.bankapp.account.AbstractAccount#withdraw(double)
	 */
	@Override
	public void withdraw(double amount) throws OverDraftLimitExceededException, 
	NotEnoughFundsException {
		if (balance < Math.abs(amount)){
			throw new NotEnoughFundsException("Account limit exceeded. "
					+ "Avaliabale balance " + this.balance);
		}
		balance -= amount;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.acme.bankapp.account.AbstractAccount#maximumAmountToWithdraw()
	 */
	@Override
	public double maximumAmountToWithdraw() {
		return balance;
	}

	/*
	 * (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.Account#getOverdraftAccount()
	 */
	@Override
	public Account getOverdraftAccount() {
		// It's not overdraft in SavingAccount
		return null;
	}
	
	/**
	 * (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.Account#hasOverdraft()
	 */
	@Override
	public boolean hasOverdraft() {
		return false;
	}	
}
